
clear
set more off
use "$base_out/DWMS_Regresiones.dta", clear


drop if secondary==1

********************************************
*********Cargo variables para interacción***
********************************************

merge 1:1 school_id using "$basein/Datos adicionales/Datos_heterogeneos.dta", gen(_het)

gen Sexo=0
replace Sexo=1 if i_gender==2

******************
***KEEP´ONLY PEC VS PEC PLUS******
******************

drop if state==10
drop if treatgroup2=="Control"

********************
**PEC PLUS vs. PEC**
********************

***Treatment***

eststo clear

gen covariate=0
gen interplus=0
gen interpec=0

foreach x in management_sted1 Sexo i_posttenure Marg { 

drop covariate interplus interpec

**Creo interacciones**

gen interplus=PEC_PLUS*`x'
gen interpec=PEC*`x'

gen  covariate=`x'

label var PEC_PLUS " " 
label var PEC " "
label var covariate " "
label var interplus " "
label var interpec " "

eststo:  reghdfe management_sted3 PEC_PLUS  interplus covariate  if treatgroup!="Control" & state!=10 & secondary!=1, a(estrato#enumerador)  vce(cluster school_id)
estadd ysumm
sum management_sted3 if e(sample)==1 & treatgroup=="PEC" & state!=10
estadd scalar ymean2=r(mean)
esttab using "$tables/DWMS_het_1_1.tex" ,  fragment se  label b(a2) se(a2) noobs nocon nonumber nomtitles nolines nogaps /// 
replace collabels(none)  ///
keep(PEC_PLUS )  star(* 0.10 ** 0.05 *** 0.01)

}


***Interaction***

eststo clear

foreach x in management_sted1 Sexo i_posttenure Marg { 

drop covariate interplus interpec

**Creo interacciones**

gen interplus=PEC_PLUS*`x'
gen interpec=PEC*`x'

gen  covariate=`x'

label var PEC_PLUS " " 
label var PEC " "
label var covariate " "
label var interplus " "
label var interpec " "

eststo:  reghdfe management_sted3 PEC_PLUS  interplus covariate  if treatgroup!="Control" & state!=10 & secondary!=1, a(estrato#enumerador)  vce(cluster school_id)
estadd ysumm
sum management_sted3 if e(sample)==1 & treatgroup=="PEC" & state!=10
estadd scalar ymean2=r(mean)
esttab using "$tables/DWMS_het_1_2.tex" ,  fragment se  label b(a2) se(a2) noobs nocon nonumber nomtitles nolines nogaps /// 
replace collabels(none)  ///
keep(interplus )  star(* 0.10 ** 0.05 *** 0.01)

}


***Other variable***

eststo clear



foreach x in management_sted1 Sexo i_posttenure Marg { 

drop covariate interplus interpec

**Creo interacciones**

gen interplus=PEC_PLUS*`x'
gen interpec=PEC*`x'

gen  covariate=`x'

label var PEC_PLUS " " 
label var PEC " "
label var covariate " "
label var interplus " "
label var interpec " "

eststo:  reghdfe management_sted3 PEC_PLUS  interplus covariate  if treatgroup!="Control" & state!=10 & secondary!=1, a(estrato#enumerador)  vce(cluster school_id)
estadd ysumm
sum management_sted3 if e(sample)==1 & treatgroup=="PEC" & state!=10
estadd scalar ymean2=r(mean)
esttab using "$tables/DWMS_het_1_3.tex" ,  fragment se ar2 label b(a2) se(a2) nocon nonumber nomtitles nolines nogaps /// 
replace collabels(none)  ///
keep(covariate ) stats(N ymean2, fmt("%9.2gc" "%9.2fc") labels("No. of obs." "Control mean")) star(* 0.10 ** 0.05 *** 0.01)
}




****************************
**********PLANEA************
****************************

clear
use "$base_out/alum_pb_2018_modified"

merge m:1 school_id using "$basein/Datos adicionales/Datos_heterogeneos.dta", gen(_het)


merge m:1 school_id using "$base_out/DWMS_Regresiones.dta", gen(_DWMS)

gen Sexo=0
replace Sexo=1 if i_gender==2


gen Sexo_alumno=0
replace Sexo_alumno=1 if genero=="M"

drop Marg

gen Marg=0

replace Marg=1 if margina=="Muy Alta y Alta"

******************
***KEEP´ONLY PEC VS PEC PLUS******
******************

drop if state==10
drop if treatgroup2=="Control"

********************
**PEC PLUS vs. PEC**
********************

***Treatment**

eststo clear

gen covariate=0
gen interplus=0
gen interpec=0


foreach x in Sexo_alumno management_sted1 Sexo i_posttenure Marg { 

drop covariate interplus interpec

**Creo interacciones**

gen interplus=PEC_Plus*`x'
gen interpec=PEC*`x'

gen  covariate=`x'

label var PEC_Plus " " 
label var PEC " "
label var covariate " "
label var interplus " "
label var interpec " "


eststo: reghdfe prom_pca  PEC_Plus covariate interplus if (treatgroup2!="Control" & state!=10) , cluster(cct_num) a(estrato)
estadd ysumm
sum prom_pca if e(sample)==1 & treatgroup=="PEC" & state!=10
estadd scalar ymean2=r(mean)
esttab using "$tables/PLANEA_het_1_1.tex" ,  fragment se label b(a2) se(a2) noobs nocon nonumber nomtitles nolines nogaps /// 
replace collabels(none)  ///
keep(PEC_Plus)  star(* 0.10 ** 0.05 *** 0.01)

}

**Interactions**

eststo clear
foreach x in Sexo_alumno management_sted1 Sexo i_posttenure Marg { 

drop covariate interplus interpec

**Creo interacciones**

gen interplus=PEC_Plus*`x'
gen interpec=PEC*`x'

gen  covariate=`x'

label var PEC_Plus " " 
label var PEC " "
label var covariate " "
label var interplus " "
label var interpec " "


eststo: reghdfe prom_pca  PEC_Plus covariate interplus if (treatgroup2!="Control" & state!=10) , cluster(cct_num) a(estrato)
estadd ysumm
sum prom_pca if e(sample)==1 & treatgroup=="PEC" & state!=10
estadd scalar ymean2=r(mean)
esttab using "$tables/PLANEA_het_1_2.tex" ,  fragment se  label b(a2) se(a2) noobs nocon nonumber nomtitles nolines nogaps /// 
replace collabels(none)  ///
keep( interplus) star(* 0.10 ** 0.05 *** 0.01)

}

**Other variable**

eststo clear
foreach x in Sexo_alumno management_sted1 Sexo i_posttenure Marg { 

drop covariate interplus interpec

**Creo interacciones**

gen interplus=PEC_Plus*`x'
gen interpec=PEC*`x'

gen  covariate=`x'

label var PEC_Plus " " 
label var PEC " "
label var covariate " "
label var interplus " "
label var interpec " "


eststo: reghdfe prom_pca  PEC_Plus covariate interplus if (treatgroup2!="Control" & state!=10) , cluster(cct_num) a(estrato)
estadd ysumm
sum prom_pca if e(sample)==1 & treatgroup=="PEC" & state!=10
estadd scalar ymean2=r(mean)
esttab using "$tables/PLANEA_het_1_3.tex" ,  fragment se ar2  label b(a2) se(a2) nocon nonumber nomtitles nolines nogaps /// 
replace collabels(none)  ///
keep(covariate) stats(N ymean2, fmt("%9.2gc" "%9.2fc") labels("No. of obs." "Control mean")) star(* 0.10 ** 0.05 *** 0.01)

}

